FROM golang:1.14-alpine AS build

WORKDIR /src/
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
    && apk add --no-cache git \
    && apk add --repository https://mirrors.ustc.edu.cn/alpine/v$(cat /etc/alpine-release | cut -c1-3)/main/ --no-cache --virtual .build-deps \
    build-base ca-certificates
ENV GOPROXY=https://goproxy.cn,direct

# RUN go env -w GOPRIVATE=gitee.com/quantum-force
ARG GOPRIVATE
ARG GIT_USER
ARG GIT_TOKEN
RUN git config --global url."https://$GIT_USER:$GIT_TOKEN@$GOPRIVATE".insteadOf "https://$GOPRIVATE"

COPY Makefile .
COPY go.mod .
RUN make download

COPY . .
RUN CGO_ENABLED=0 make build

FROM scratch
COPY --from=build /etc/ssl/certs/ca-certificates.crt \
                  /etc/ssl/certs/
COPY --from=build /src/target/bilinaccount \
                  /bin/
ENTRYPOINT ["/bin/bilinaccount"]
